<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="wangzhichao">
	<title>生成卡片申请单/制卡任务单</title>
	<!--js库及样式-->
	<script language="javascript" type="text/javascript" src="../script/common.js"></script>
	<script language="javascript" type="text/javascript">
		//全局变量
		var type="";				//卡片类型	
		var orderId="";				//申请单类型
		var titlename="";			//标题名称
		var ispersent="no";		//是否有个人信息
		var location1 = {};
		var detail_editable = true ;
		function load(){
			Eui.showNavigation();
			setPages(["mainview","listview","detview"]);
			location1 = Common.cOrg()
			if(location1.orgLevel == Constants.ORG_LEVEL_HQ){
				$("formtitle").innerHTML = "制卡任务单";
				$("restrictedOrgTd").innerHTML = "<label>使用区域</label> <span id='restrictedOrg'></span>";
			}else{
				$("formtitle").innerHTML = "卡片申请单";
			}
		}
		//保存制卡申请单
		function onSave(){
			if(!checkForm(demandform))return;
			if(!(showQuestion("您确认创建单据吗?"))){
				return;
			}
			var apply = Common.getValues(demandform);
			titlename=apply.cardTypeName;
			if(ispersent=="no"){
				DWR.call("cardRequestService.createReqOrder",apply.cardType,apply.completeDate,apply.amount,apply.requestComment,false,apply.restrictedOrg,function(showapply){
					 showapply.cardRequestOrder.cardType=showapply.cardType.name;
				 	 showapply.cardRequestOrder.status=Common.getText("cardbill_status",showapply.cardRequestOrder.status);
					 showapply.cardRequestOrder.createTime=Format.formatToMM(showapply.cardRequestOrder.createTime);
					 if(location1.orgLevel == Constants.ORG_LEVEL_HQ){
					 	showapply.cardRequestOrder.restrictedOrg = showapply.organization.name;
					 }
					 Common.showDetail("detview",showapply.cardRequestOrder);
					 showInformation("创建单据成功!");
					 switchPage('detview');
				},{disCtrl:$('saveBtn')});
			}else if(ispersent=="is"){
				DWR.call("cardRequestService.createReqOrder",apply.cardType,apply.completeDate,0,null,true,apply.restrictedOrg,function(showapply){
					orderId=showapply.cardRequestOrder.id;
					type=showapply.cardRequestOrder.cardType;
					requestframe.document.location.href = "request_order_detail.html";
					switchPage("listview")
				},{disCtrl:$('saveBtn')});
			}
		}
		//选择是否有个人信息
		function changeType(type){
			if(type=="ispersent"){
				changeSpan("personalHasInfo");
			}
			else if(type=="nopersent"){
				changeSpan("personalNoInfo");
			}
		}
		//返回方法
		function backShow(){
		    demandform.reset();
			$('cardamount').innerHTML = "";
			$("requestComment").innerHTML = "";
			$("completeDate1").innerHTML = "";
			
			$("changeType").innerHTML ="";
			$('buttondiv').innerHTML = "";
			$("restrictedOrgSpan").style.display="none";
			switchPage("mainview");
		}
		//选择卡片类型
		function selCardType(){
			var v = openDialogFrame("/basic/card_type_list.html",'选择卡片类型',464,700);
			var anonymous=false;
		    if (v){
			    demandform.cardType.value=v[0];
				demandform.cardTypeName.value = v[1];
			 	demandform.baseCardType.value=v[5];
				anonymous=v[6];
				if(location1.orgLevel == Constants.ORG_LEVEL_HQ){
					$("restrictedOrgSpan").style.display=""
					DWR.call("storeQueryService.getCardAreas",function(result){
						Common.initDict(demandform.restrictedOrg,result,"请选择","id","name");	
					})
				}
			}
			switch(parseInt(demandform.baseCardType.value)){
				case BaseCardType.PERSONAL:					//个人卡1
				case BaseCardType.COMPANY:						//单位卡2
					if(anonymous==true){
						changeSpan("personalNoName");
					}else{
						changeSpan("personalName");
					}
					break;
				case BaseCardType.PSAM:						//PSAM卡3
				case BaseCardType.OPERATOR:					//操作员卡4
					changeSpan("personalNoName");
			}
			
		}
		function changeSpan(mark){
			if(mark == "personalHasInfo"){
				ispersent="is"
				$('cardamount').innerHTML = "";
				$("completeDate1").innerHTML = "";
				$("requestComment").innerHTML =  "";
				$('buttondiv').innerHTML = "<button type='button' id='saveBtn' name='saveBtn' onclick=onSave()>下一步</button>";
			}else if(mark == "personalNoInfo"){
				ispersent="no"
				Eui.initDateInput("completeDate1","完成日期","demandform","completeDate","futureDate");
				if(location1.orgLevel >= Constants.REQUEST_LOWEST_LEVEL){
					$('cardamount').innerHTML = "<label>需求数量</label> <input type='text' name='amount' onblur=checkV(this,'positiveInt',true) maxlength=9><span class='des'>*</span>";
				}else{
					//$('cardamount').innerHTML = "<label>需求数量</label> <input type='text' name='amount' onblur=checkV(this,'positiveInt',true) maxlength=9><span class='des'>*</span><button type='button' name='butt' onclick='onNew()'>合并下级申请单</button>";
					$('cardamount').innerHTML = "<label>需求数量</label> <input type='text' name='amount' onblur=checkV(this,'positiveInt',true) maxlength=9><span class='des'>*</span>";
				}
				$("requestComment").innerHTML =  "<label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <input type='text' name='requestComment' id='requestComment' maxlength=64>";
				$('buttondiv').innerHTML = "<button type='button' id='saveBtn' name='saveBtn' onclick=onSave()>保    存</button>";
			}else if(mark == "personalNoName"){
				ispersent="no"
				Eui.initDateInput("completeDate1","完成日期","demandform","completeDate","futureDate");
				if(location1.orgLevel >= Constants.REQUEST_LOWEST_LEVEL){
					$('cardamount').innerHTML = "<label>需求数量</label> <input type='text' name='amount' onblur=checkV(this,'positiveInt',true) maxlength=9><span class='des'>*</span>";
				}else{
					//$('cardamount').innerHTML = "<label>需求数量</label> <input type='text' name='amount' onblur=checkV(this,'positiveInt',true) maxlength=9><span class='des'>*</span><button type='button' name='butt' onclick='onNew()'>合并下级申请单</button>";
					$('cardamount').innerHTML = "<label>需求数量</label> <input type='text' name='amount' onblur=checkV(this,'positiveInt',true) maxlength=9><span class='des'>*</span>";
				}
				$("requestComment").innerHTML =  "<label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <input type='text' name='requestComment' id='requestComment' maxlength=64>";
				$('buttondiv').innerHTML = "<button type='button' id='saveBtn' name='saveBtn' onclick=onSave()>保    存</button>";
				$("changeType").innerHTML = "";
			}else if(mark == "personalName"){
				ispersent="is"
				$("completeDate1").innerHTML = "";
				$("changeType").innerHTML = "<input type='radio' name='persent' onclick='changeType(\"ispersent\")' checked='true'><label>有个人信息</label> <input type='radio' name='persent' onclick='changeType(\"nopersent\")'><label>无个人信息</label>";
				$('cardamount').innerHTML = "";
				$("requestComment").innerHTML = "";
				$('buttondiv').innerHTML = "<button type='button' id='saveBtn' name='saveBtn' onclick=onSave()>下一步</button>";
			}
		}
		function onNew(){
			type=demandform.cardType.value;
			var isPersent = false;
			var v = openDialogFrame("/store/sel_req_order.html?ct="+type+"&isPersent="+isPersent,"选择申请单",500,710);
			if (v){
				demandform.amount.value = v;
			}
		}
	</script>
</head>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
		<!--新增制卡申请单-->
	<div class="mainview" id="mainview">
		<form id="demandform" name="demandform">
			<input type="hidden" name="organization">
			<input type="hidden" name="baseCardType">
			<input type="hidden" name="cardType">
			<div class="form">
				<div class="formTitle">
					<span id="formtitle"></span>
				</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0>
					<tr>
						<td>
							<label>卡片类型</label> <input type="text" name="cardTypeName" onblur="checkV(this,'futureDate',true);" maxlength=20 disabled=true><a class=orga title="选择卡片规格" href="javascript:void(0)" onclick="selCardType()">&nbsp;&nbsp;</a><font class="des">*</font>
						</td>
						<td id="cardamount">
						</td>
					</tr>
					<tr>
						<td id="completeDate1">
						</td>
						<td id="requestComment">
						</td>
					</tr>
					<tr>
						<td id="restrictedOrgSpan" style="display:none">
							<label>使用区域</label> <select name='restrictedOrg'  onblur=checkV(this,'',true)></select><span class='des'>*</span>
						</td>
					</tr>
					<tr>
						<td id="changeType">
						</td>
					</tr>
				</table>
			</div>
			<div id="buttondiv"></div>
		</form>
	</div>
	<div class="listview" id="listview" style='display:none;'>
		<iframe id="requestframe" name="requestframe" style="width:100%;height:90%;overflow:auto;" frameborder=0 src=""></iframe>
	</div>
	<div class="detview" id="detview" style='display:none;'>
		<form id="makecardform" name="makecardform">
		    <input type="hidden" id="id" name="id">
			<div class=form>
			<div class="formTitle">单据明细</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
					<tr>
						<td><label>单据编号</label> <span id="id"></span></td>
						<td><label>卡片类型</label> <span id="cardType"></span></td>
					</tr>
					<tr>
						<td><label>需求数量</label> <span id="amount"></span></td>
						<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <span id="status"></span></td>
					</tr>
					<tr>
						<td><label>创建时间</label> <span id="createTime"></span></td>
						<td><label>完成日期</label> <span id='completeDate'></span></td>
					</tr>
					<tr>
						<td id="restrictedOrgTd" colspan="2"></td>
					</tr>
					<tr>
						<td colspan="2"><label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <span id="requestComment"></span></td>
					</tr>
				</table>
			</div>
		</form>
		<p><span id="query"></span><button type="button" onclick="backShow()">返   回</button></p>
	</div>
</body>
</html>